using UnityEngine;

namespace ProceduralPrimitivesUtil
{
	public class ChamferPlane : PPBase
	{
		[Header("Basic parameters")]
		public float width = 2f;

		public float length = 2f;

		public float fillet = 0.4f;

		[Header("Segments")]
		public int widthSegs = 10;

		public int lengthSegs = 10;

		public int filletSegs = 5;

		[Header("Mapping Coordinates")]
		public bool generateMappingCoords = true;

		public bool realWorldMapSize;

		public Vector2 UVOffset = new Vector2(0f, 0f);

		public Vector2 UVTiling = new Vector2(1f, 1f);

		[Header("Others")]
		public bool flipNormals;

		protected override void CreateMesh()
		{
			m_mesh.name = "ChamferPlane";
			length = Mathf.Clamp(length, 1E-05f, 10000f);
			width = Mathf.Clamp(width, 1E-05f, 10000f);
			float num = ((length < width) ? length : width);
			fillet = Mathf.Clamp(fillet, 1E-05f, num / 2f);
			lengthSegs = Mathf.Clamp(lengthSegs, 1, 100);
			widthSegs = Mathf.Clamp(widthSegs, 1, 100);
			filletSegs = Mathf.Clamp(filletSegs, 1, 100);
			float num2 = length * 0.5f;
			float num3 = width * 0.5f;
			float num4 = fillet * 0.5f;
			float num5 = num2 - fillet;
			float num6 = num3 - fillet;
			float num7 = num2 - num4;
			float num8 = num3 - num4;
			Vector2 vector = (realWorldMapSize ? new Vector2(1f, 1f) : new Vector2(fillet / num3, fillet / num2));
			vector = new Vector2(UVTiling.x * vector.x, UVTiling.y * vector.y);
			Vector2 vector2 = (realWorldMapSize ? new Vector2(1f, 1f) : new Vector2(num6 / num3, num5 / num2));
			vector2 = new Vector2(UVTiling.x * vector2.x, UVTiling.y * vector2.y);
			Vector2 vector3 = (realWorldMapSize ? new Vector2(1f, 1f) : new Vector2(fillet / width, num5 / num2));
			vector3 = new Vector2(UVTiling.x * vector3.x, UVTiling.y * vector3.y);
			Vector2 vector4 = (realWorldMapSize ? new Vector2(1f, 1f) : new Vector2(num6 / num3, fillet / length));
			vector4 = new Vector2(UVTiling.x * vector4.x, UVTiling.y * vector4.y);
			CreatePlane(pivotOffset + Vector3.zero, m_rotation * Vector3.forward, m_rotation * Vector3.right, num6 * 2f, num5 * 2f, widthSegs, lengthSegs, generateMappingCoords, realWorldMapSize, UVOffset + new Vector2(num4 / num3, num4 / num2), vector2, flipNormals);
			CreatePlane(pivotOffset + m_rotation * new Vector3(0f, 0f, num7), m_rotation * Vector3.forward, m_rotation * Vector3.right, num6 * 2f, fillet, widthSegs, filletSegs, generateMappingCoords, realWorldMapSize, UVOffset + new Vector2(num4 / num3, (length - fillet) / length), vector4, flipNormals);
			CreatePlane(pivotOffset + m_rotation * new Vector3(0f, 0f, 0f - num7), m_rotation * Vector3.forward, m_rotation * Vector3.right, num6 * 2f, fillet, widthSegs, filletSegs, generateMappingCoords, realWorldMapSize, UVOffset + new Vector2(num4 / num3, 0f), vector4, flipNormals);
			CreatePlane(pivotOffset + m_rotation * new Vector3(0f - num8, 0f, 0f), m_rotation * Vector3.forward, m_rotation * Vector3.right, fillet, num5 * 2f, filletSegs, lengthSegs, generateMappingCoords, realWorldMapSize, UVOffset + new Vector2(0f, num4 / num2), vector3, flipNormals);
			CreatePlane(pivotOffset + m_rotation * new Vector3(num8, 0f, 0f), m_rotation * Vector3.forward, m_rotation * Vector3.right, fillet, num5 * 2f, filletSegs, lengthSegs, generateMappingCoords, realWorldMapSize, UVOffset + new Vector2((width - fillet) / width, num4 / num2), vector3, flipNormals);
			CreateCircle(pivotOffset + m_rotation * new Vector3(num3 - fillet, 0f, num2 - fillet), m_rotation * Vector3.forward, m_rotation * Vector3.right, fillet, filletSegs, filletSegs, sliceOn: true, 0f, 90f, generateMappingCoords, realWorldMapSize, UVOffset + new Vector2(num6 / width, num5 / length), vector, flipNormals);
			CreateCircle(pivotOffset + m_rotation * new Vector3(num3 - fillet, 0f, 0f - num5), m_rotation * Vector3.forward, m_rotation * Vector3.right, fillet, filletSegs, filletSegs, sliceOn: true, 90f, 180f, generateMappingCoords, realWorldMapSize, UVOffset + new Vector2(num6 / width, (0f - num5) / length), vector, flipNormals);
			CreateCircle(pivotOffset + m_rotation * new Vector3(0f - num6, 0f, 0f - num5), m_rotation * Vector3.forward, m_rotation * Vector3.right, fillet, filletSegs, filletSegs, sliceOn: true, 180f, 270f, generateMappingCoords, realWorldMapSize, UVOffset + new Vector2((0f - num6) / width, (0f - num5) / length), vector, flipNormals);
			CreateCircle(pivotOffset + m_rotation * new Vector3(0f - num6, 0f, num2 - fillet), m_rotation * Vector3.forward, m_rotation * Vector3.right, fillet, filletSegs, filletSegs, sliceOn: true, 270f, 360f, generateMappingCoords, realWorldMapSize, UVOffset + new Vector2((0f - num6) / width, num5 / length), vector, flipNormals);
		}
	}
}
